package com.neusoft.Shixun.controller;

import com.neusoft.Shixun.dto.CheckoutRequestWithClientDto;
import com.neusoft.Shixun.po.CheckoutRequest;
import com.neusoft.Shixun.po.OutgoingRequest;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.CheckoutRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin("*")
@RequestMapping("/CheckoutRequestController")
public class CheckoutRequestController {

    @Autowired
    private CheckoutRequestService checkoutRequestService;

    @GetMapping
    public ResponseBean<List<CheckoutRequest>> getAllCheckoutRequests() {
        return checkoutRequestService.getAllCheckoutRequests();
    }

    @GetMapping("/getCheckoutRequests")
//    条件查询
    public ResponseBean<List<CheckoutRequestWithClientDto>> getCheckoutRequests(
            @RequestParam(required = false) String clientName,
            @RequestParam(required = false) String isSelfCare) {
        return checkoutRequestService.getCheckoutRequests(clientName, isSelfCare);
    }

    @GetMapping("/getCheckoutRequestsByCareTakerId")
    //   健康管家查询自己服务客户的退住申请
    public ResponseBean<List<CheckoutRequestWithClientDto>> getCheckoutRequestsByCareTakerId(
            @RequestParam Integer careTakerId,
            @RequestParam(required = false) String clientName) {
        return checkoutRequestService.getCheckoutRequestsByCareTakerId(careTakerId, clientName);
    }

    @PostMapping("/passCheckoutRequest")
//    通过退住审核
    public ResponseBean<Integer> passCheckoutRequest(@RequestBody CheckoutRequest checkoutRequest) {
        return checkoutRequestService.passCheckoutRequest(checkoutRequest);
    }

    @GetMapping("/{id}")
    public ResponseBean<CheckoutRequest> getCheckoutRequestById(@PathVariable Integer id) {
        return checkoutRequestService.getCheckoutRequestById(id);
    }

    @PostMapping("/addCheckoutRequest")
//   健康管家提出退住申请
    public ResponseBean<Integer> addCheckoutRequest(@RequestBody CheckoutRequest checkoutRequest) {
        return checkoutRequestService.addCheckoutRequest(checkoutRequest);
    }

    @PutMapping("/{id}")
    public ResponseBean<Integer> updateCheckoutRequest(@PathVariable Integer id, @RequestBody CheckoutRequest checkoutRequest) {
        checkoutRequest.setRequestId(id);
        return checkoutRequestService.updateCheckoutRequest(checkoutRequest);
    }

    @DeleteMapping("/{id}")
    public ResponseBean<Integer> deleteCheckoutRequest(@PathVariable Integer id) {
        return checkoutRequestService.deleteCheckoutRequest(id);
    }
}